﻿#ifndef NEWFORMULASTANDARDITEMMODEL_H
#define NEWFORMULASTANDARDITEMMODEL_H

#include <QStandardItemModel>
#include "product.h"

class NewFormulaStandardItemModel : public QStandardItemModel
{
    Q_OBJECT
public:

    enum WidgetType{
        NewFormmula,    //新建公式
        CombineProduct, //装配商品
        SplitProduct    //拆分商品
    };

    Q_ENUM(WidgetType)

    QStringList header;

    explicit NewFormulaStandardItemModel(QObject *parent = nullptr);

    bool setData(const QModelIndex &index, const QVariant &value, int role) override;

    QVariant data(const QModelIndex &index, int role) const override;

    void setWidgetType(WidgetType widgetType);

    void insertData(Product &product, int defaultCount);

    void insertData(QList<Product*> products, int defaultCount);\

    void appendData(Product &product);

    void appendData(QList<Product*> products);

    QList<Product*> currentProducts();

    void reset();

    void refreshTotal();

    QString getAllInPrices();

signals:
    void updateTotal(double total);

public slots:

private:
    QList<Product*> products;
    WidgetType widgetType;
};

#endif // NEWFORMULASTANDARDITEMMODEL_H
